home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / shadez.swf / scripts / Local / CMain.as < prev    next >
Text File  |  2011-08-19  |  7KB  |  222 lines

  1. package Local
  2. {
  3.    import Local.Draw.CScreen;
  4.    import Local.Draw.CScreen_Debrief;
  5.    import Local.Draw.CScreen_LoadingLevel;
  6.    import Local.External.CKongregate;
  7.    import Local.Game.CGame;
  8.    import STC9.System.CProfiler;
  9.    import flash.display.MovieClip;
  10.    import flash.display.StageAlign;
  11.    import flash.display.StageScaleMode;
  12.    import flash.events.Event;
  13.    import flash.geom.Rectangle;
  14.    
  15.    public class CMain extends MovieClip
  16.    {
  17.       
  18.       public static var mMinSize:Rectangle = new Rectangle(0,0,700,550);
  19.       
  20.       public static var mMaxSize:Rectangle = new Rectangle(0,0,700,550);
  21.       
  22.       public static var mSize:Rectangle = new Rectangle(0,0,700,550);
  23.        
  24.       
  25.       private var mScreens:CScreen;
  26.       
  27.       public var mcTimer:MovieClip;
  28.       
  29.       public var mProfiler:CProfiler;
  30.       
  31.       private var mGame:CGame;
  32.       
  33.       public function CMain()
  34.       {
  35.          if(true)
  36.          {
  37.             super();
  38.             if(true)
  39.             {
  40.                addEventListener(Event.ADDED_TO_STAGE,Initialize);
  41.             }
  42.             opaqueBackground = 0;
  43.          }
  44.       }
  45.       
  46.       public function UpdateTimer(param1:int) : void
  47.       {
  48.          var _loc2_:String = null;
  49.          var _loc3_:String = null;
  50.          var _loc4_:String = null;
  51.          var _loc5_:String = null;
  52.          if(!CGlobal.mShowVideoTimer)
  53.          {
  54.             return;
  55.          }
  56.          _loc2_ = String(Math.floor(param1 % CGame.SECONDS));
  57.          _loc3_ = String(Math.floor(param1 / CGame.SECONDS) % 60);
  58.          _loc4_ = String(Math.floor(param1 / (CGame.SECONDS * 60)) % 60);
  59.          _loc5_ = String(Math.floor(param1 / (CGame.SECONDS * 60 * 60)) % 24);
  60.          mcTimer.tbTimer.text = p0(_loc5_) + ":" + p0(_loc4_) + ":" + p0(_loc3_) + "." + p0(_loc2_);
  61.       }
  62.       
  63.       private function e_GAME_LOADED(param1:Event = null) : void
  64.       {
  65.          var _loc2_:CScreen_LoadingLevel = null;
  66.          _loc2_ = CScreen_LoadingLevel(param1.currentTarget);
  67.          var _loc3_:*;
  68.          mGame = _loc3_ = _loc2_.mGame;
  69.          addChildAt(_loc3_,0);
  70.          mScreens.Deactivate();
  71.          mGame.addEventListener(CGame.GAME_COMPLETE,e_GAME_COMPLETE);
  72.          mGame.addEventListener(CGame.GAME_EXIT,e_GAME_EXIT);
  73.          mGame.addEventListener(CGame.GAME_DIED,e_GAME_DIED);
  74.          CProfiler.Reset();
  75.          e_RESIZE();
  76.       }
  77.       
  78.       public function Initialize(param1:Event = null) : void
  79.       {
  80.          removeEventListener(Event.ADDED_TO_STAGE,Initialize);
  81.          stage.align = StageAlign.TOP_LEFT;
  82.          stage.scaleMode = StageScaleMode.NO_SCALE;
  83.          addEventListener(Event.ENTER_FRAME,Update);
  84.          stage.addEventListener(Event.RESIZE,e_RESIZE);
  85.          CGlobal.Open();
  86.          mProfiler = new CProfiler("left","fpsonly");
  87.          if(CGlobal.mProfiler)
  88.          {
  89.             addChild(mProfiler);
  90.          }
  91.          mScreens = new CScreen();
  92.          addChildAt(mScreens,0);
  93.          ┬º┬ºpush(mScreens);
  94.          ┬º┬ºpush("main");
  95.          if(true)
  96.          {
  97.             ┬º┬ºpop().AddScreen(┬º┬ºpop(),new Screen_Main());
  98.             mScreens.AddScreen("selectlevel",new Screen_SelectLevel());
  99.             mScreens.AddScreen("loadinglevel",new Screen_LoadingLevel()).addEventListener(CScreen_LoadingLevel.GAME_LOADED,e_GAME_LOADED);
  100.             mScreens.AddScreen("debrief",new Screen_Debrief());
  101.             ┬º┬ºpush(mScreens);
  102.             ┬º┬ºpush("main");
  103.          }
  104.          ┬º┬ºpop().GetScreen(┬º┬ºpop()).Activate();
  105.          mcTimer.visible = CGlobal.mShowVideoTimer;
  106.          CKongregate.Load(this);
  107.          e_RESIZE();
  108.       }
  109.       
  110.       private function e_GAME_DIED(param1:Event = null) : void
  111.       {
  112.          if(true)
  113.          {
  114.             e_GAME_COMPLETE(param1,"died");
  115.          }
  116.       }
  117.       
  118.       private function e_GAME_COMPLETE(param1:Event = null, param2:String = "complete") : void
  119.       {
  120.          if(true)
  121.          {
  122.             CScreen_Debrief.mScore = mGame.mScore;
  123.             if(true)
  124.             {
  125.                CScreen_Debrief.mGameState = param2;
  126.                if(true)
  127.                {
  128.                   mGame.Dispose();
  129.                   if(true)
  130.                   {
  131.                      removeChild(mGame);
  132.                      if(true)
  133.                      {
  134.                         mGame = null;
  135.                         addChildAt(mScreens,0);
  136.                      }
  137.                      CProfiler.Reset();
  138.                   }
  139.                   e_RESIZE();
  140.                }
  141.                UpdateTimer(0);
  142.             }
  143.             mScreens.GetScreen("debrief").Activate();
  144.          }
  145.       }
  146.       
  147.       public function e_RESIZE(param1:Event = null) : void
  148.       {
  149.          if(true)
  150.          {
  151.             ┬º┬ºpush(mGame);
  152.             if(true)
  153.             {
  154.                ┬º┬ºgoto(addr21);
  155.             }
  156.             ┬º┬ºpop().Resize(mSize.width,mSize.height);
  157.          }
  158.          addr21:
  159.          if(┬º┬ºpop())
  160.          {
  161.             ┬º┬ºpush(mGame);
  162.          }
  163.       }
  164.       
  165.       private function p0(param1:String) : String
  166.       {
  167.          ┬º┬ºpush(param1);
  168.          if(true)
  169.          {
  170.             if(┬º┬ºpop().length < 2)
  171.             {
  172.                ┬º┬ºpush("0" + param1);
  173.                if(true)
  174.                {
  175.                }
  176.                ┬º┬ºgoto(addr31);
  177.             }
  178.             else
  179.             {
  180.                ┬º┬ºpush(param1);
  181.             }
  182.             ┬º┬ºpush(┬º┬ºpop());
  183.          }
  184.          addr31:
  185.          return ┬º┬ºpop();
  186.       }
  187.       
  188.       public function Update(param1:Event = null) : void
  189.       {
  190.          CProfiler.StopProfile("_frame.Update");
  191.          mProfiler.Update(true);
  192.          CProfiler.StartProfile("_frame.Update");
  193.          ┬º┬ºpush(mGame);
  194.          if(true)
  195.          {
  196.             if(┬º┬ºpop())
  197.             {
  198.                addr30:
  199.                mGame.Update();
  200.             }
  201.             ┬º┬ºpush(mScreens);
  202.             if(true)
  203.             {
  204.                if(┬º┬ºpop().parent)
  205.                {
  206.                   addr44:
  207.                   mScreens.Process();
  208.                }
  209.                return;
  210.             }
  211.             ┬º┬ºgoto(addr44);
  212.          }
  213.          ┬º┬ºgoto(addr30);
  214.       }
  215.       
  216.       private function e_GAME_EXIT(param1:Event = null) : void
  217.       {
  218.          e_GAME_COMPLETE(param1,"exit");
  219.       }
  220.    }
  221. }
  222.